package com.mlk.stock.controller;

import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.stock.service.StockService;
import com.mlk.stock.vo.EngStockDetailVO;
import com.mlk.waste.service.WasteTypeTreeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Controller
@RequestMapping("/eng/stock")
public class StockController {

    @Resource
    private StockService stockService;

    @Resource
    private WasteTypeTreeService wasteTypeTreeService;

    /**
     * 返回到库存首页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "stock/stock";
    }


    /**
     * 获取节点树
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public ServerResponse list(){
        return this.wasteTypeTreeService.queryAllNode();
    }

    /**
     * 盘点操作
     * @return
     */
    @ResponseBody
    @RequestMapping("stockCal")
    public ServerResponse stockCal(Integer typeId, BigDecimal num){
        return this.stockService.stockCal(typeId,num);
    }

    /**
     * 库存明细
     * @return
     */
    @RequestMapping("stockDeatil")
    public String stockDeatil(Integer typeId, Model model){
        model.addAttribute("typeId",typeId);
        return "stock/stockDeatil";
    }

    /**
     * 库存明细列表
     * @param detail
     * @return
     */
    @RequestMapping("detailPageList")
    @ResponseBody
    public Pager detailPageList(EngStockDetailVO detail){
        return this.stockService.detailPageList(detail);
    }

}
